package com.meta.util;

import com.meta.nd.vo.ReturnMessage;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtils {
    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);


        try {
            throwable.printStackTrace(pw);
            return sw.toString();


        } finally {
            pw.close();
        }
    }

    public static ReturnMessage buildReturnMessage(Throwable throwable){
        return ReturnMessage.buildFailMessage(throwable.getMessage(),getStackTrace(throwable));
    }
}
